// function qq() {
//     $.ajax({
//         url: "https://v2.alapi.cn/api/one",
//         data: {
//             token: "8iPjfSJgxpV7YDfD",
//             format: "json",
//         },
//         dataType: "json",
//         type: "GET",
//         success: function (result) {
//             console.log(result);
//         }
//     });
// };

document.cookie = " "
function sendedMsg() {
    $("#inputStatus").text("对方正在输入...");
    var msg = document.getElementById("getMsg").value;
    $("#sendedMsg").text("You: " + msg);
    var msgTo = msg;
    var $usermsg = $(`
    <div id="replaceItem"></div>
                    <div class="userChat">
                        <div class="userChatImg">
                            <img src="./image/head.png" alt="">
                        </div>
                        <div class="userChatText">
                            <p>You</p>
                            <div class="usermsg">
                                <p>${msg}</p>
                            </div>
                        </div>
                    </div>
    `);

    if (msg != "") {
        $("#replaceItem").replaceWith($usermsg);


        document.getElementById("getMsg").value = "";
        var div = document.getElementsByClassName('chatFrame');
        div.scrollTop = div.scrollHeight;
    }
    var session = "";
    $.ajax({
        url: "http://101.34.87.140:2333/chatbot/index.php?message=" + msgTo + "&session=" + session + "",
        type: "GET",
        dataType: "json",
        success: function (result) {
            eval("var a=" + result);
            var session = a.result.session_id;
            document.cookie = session;
            var resultMsg = a.result.context.SYS_PRESUMED_HIST[1];
            var $botmsg = $(`
            <div id="replaceItem"></div>
            <div class="botChat">
            <div class="botChatImg">
                <img src="./image/aihead.bmp" alt="">
            </div>
            <div class="botChatText">
                <p>Kizuna Ai</p>
                <div class="botmsg">
                    <p>${resultMsg}</p>
                </div>
            </div>
        </div>
            `);
            $("#replaceItem").replaceWith($botmsg);
            $("#inputStatus").text("在线");
            $("#sendedMsg").text("Kizuna Ai: " + resultMsg);
        },
    })
}


$("#flyMsg").click(function () {
    sendedMsg();
});


$(function () {
    $(document).keydown(function (e) {
        if (13 == e.keyCode) {
            sendedMsg();
        }
    }
    )
});